<?php $this->load->view('header'); ?>

<div class="wrap-detail-project wrap-dashboard">
    <div class="container container-dashboard">
        <div class="row">
            <div class="col-lg-9 col-md-9 col-sm-9 col-xs-12 no-padding">
                <ul class="tab-dashboard">
                    <li class="active"><a href=""><?php echo $this->lang->line("Hire")?></a></li>
                    <li><a href=""><?php echo $this->lang->line("Manage")?></a></li>
                    <li><a href=""><?php echo $this->lang->line("Setting")?></a></li>
                </ul>
            </div>
            <div class="col-lg-3 col-md-3 col-sm-3 col-xs-12 no-padding">
                <div class="search-dashboard">
                    <form action="" method="post" id="frm-search">
                        <select name="search_type" class="search-type">
                            <option><?php echo $this->lang->line('Freelancers')?></option>
                            <option><?php echo $this->lang->line('Jobs')?></option>
                        </select>
                        <input type="text" name="search" class="search" placeholder="<?php echo $this->lang->line('Find freelancers');?>">
                        <button type="submit" class="btn-search glyphicon glyphicon-search"></button>
                    </form>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 no-padding">
                <ul class="nav nav-pills tab-child">
                    <li><a href="<?php echo site_url('buyer/viewMyProjects');?>"><?php echo $this->lang->line("My jobs")?></a></li>
                    <li><a href="<?php echo site_url('buyer/savedFreelancers');?>"><?php echo $this->lang->line("Saved freelancers")?></a></li>
                    <li class="active"><a href="<?php echo site_url('buyer/messages');?>"><?php echo $this->lang->line("Messages")?></a></li>
                    <li><a href=""><?php echo $this->lang->line("All updates")?></a></li>
                </ul>
            </div>
        </div>
        <div class="row app-panel messaged">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 no-padding">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 no-padding app-panel-title">
                    <div class="col-lg-2 col-md-2 col-sm-2 col-xs-3 padding-right">
                        <a href="<?php echo site_url('buyer/createMessage'); ?>" class="btn btn-post-job"><?php echo $this->lang->line('New message')?></a>
                    </div>
                    <div class="col-lg-10 col-md-10 col-sm-10 col-xs-9 no-padding">
                        <form action="" method="post">
                            <input type="text" name="search_job" class="form-control form-input" placeholder="<?php echo $this->lang->line('Search Messages')?>">
                            <button type="submit" class="btn-search glyphicon glyphicon-search"></button>
                        </form>
                    </div>
                </div>
                <div class="col-lg-3 col-md-3 col-sm-3 col-xs-3 no-padding col-left">
                    <ul>
                        <li class="active">
                            <a href="<?php echo site_url('buyer/messages#inbox')?>"><?php echo $this->lang->line('Inbox')?>
                                <?php echo ($count_unread->num_rows() > 0)?' (<span id="count_unread">'.$count_unread->num_rows().'</span>)':''?>
                            </a>
                        </li>
                        <li>
                            <a href="<?php echo site_url('buyer/messages#send')?>"><?php echo $this->lang->line('Send')?>
                                <?php echo ($count_message_send->num_rows() > 0)?' (<span id="count_send">'.$count_message_send->num_rows().'</span>)':''?>
                            </a>
                        </li>
                        <li>
                            <a href="<?php echo site_url('buyer/messages#archive')?>"><?php echo $this->lang->line('Archive')?>
                                <?php echo ($count_archive->num_rows() > 0)?' (<span id="count_archive">'.$count_archive->num_rows().'</span>)':''?>
                            </a>
                        </li>
                    </ul>
                </div>
                <div class="col-lg-9 col-md-9 col-sm-9 col-xs-9 padding-left">
                    <?php if(validation_errors() != null){?>
                        <div class="alert alert-danger">
                            <button data-dismiss="alert" class="close"></button>
                            <i class="fa fa-times-circle"></i>
                            <strong><?php echo $this->lang->line('Message')?></strong>
                            <ul>
                                <?php echo validation_errors('<li>', '</li>'); ?>
                            </ul>
                        </div>
                    <?php } ?>
                    <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 no-padding">
                        <form action="" method="post" id="frm-send-message" enctype="multipart/form-data">
                            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 no-padding form-group">
                                <label><?php echo $this->lang->line('Send to')?></label>
                                <input type="text" id='send_to' name="send_to" class="form-control" value="<?php echo set_value('send_to');?>">
                                <?php echo form_error('send_to') ?>
                            </div>
                            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 no-padding form-group">
                                <label><?php echo $this->lang->line('Subject')?></label>
                                <input type="text" id='subject' name="subject" class="form-control" value="<?php echo set_value('subject');?>">
                                <?php echo form_error('subject') ?>
                            </div>
                            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 no-padding form-group">
                                <label><?php echo $this->lang->line('Message')?></label>
                                <textarea id='message' name="message" class="form-control" rows="10"><?php echo set_value('message'); ?></textarea>
                                <?php echo form_error('message') ?>
                            </div>
                            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 no-padding form-group">
                                <div class="btn-attachment">
                                    <span><i class="clip-plus-circle"></i></span>
                                    <span class="label-attach"><?php echo $this->lang->line('Attach a file')?></span>
                                    <input type="file" id='attach_file' name="attach_file">
                                </div>
                            </div>
                            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 no-padding form-group">
                                <button type="submit" class='btn btn-send' name="btn_send" value="btn_send"><?php echo $this->lang->line('Send')?></button>
                                <a href="<?php echo site_url('buyer/messages')?>"><?php echo $this->lang->line('Cancel')?></a>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<?php $this->load->view('footer'); ?>

<script type="text/javascript">
    $(document).ready(function () {
        $("#frm-send-message").validate({
            errorElement: "span", // contain the error msg in a span tag
            errorClass: 'help-block',
            errorPlacement: function (error, element) {
                if (element.attr("type") == "radio" ) {
                    error.insertAfter($(element).closest('.form-group').children('div').children().last());
                } else if (element.attr("name") == "dd" || element.attr("name") == "mm" || element.attr("name") == "yyyy") {
                    error.insertAfter($(element).closest('.form-group').children('div'));
                } else if (element.attr("type") == "file" ) {
                    error.insertAfter($(element).closest('.form-group').children('div').last());
                } else if (element.attr("type") == "checkbox" ) {
                    error.appendTo($(element).closest('.form-group'));
                } else {
                    error.insertAfter(element);
                }
            },
            highlight: function (element) {
                $(element).closest('.help-block').removeClass('valid');
                $(element).closest('.form-group').removeClass('has-success').addClass('has-error').find('.symbol').removeClass('ok').addClass('required');
            },
            unhighlight: function (element) { // revert the change done by hightlight
                $(element).closest('.form-group').removeClass('has-error');
            },
            success: function (label, element) {
                label.addClass('help-block valid');
                $(element).closest('.form-group').removeClass('has-error').addClass('has-success').find('.symbol').removeClass('required').addClass('ok');
            },
            rules: {
                "send_to": {
                    required: true
                },
                "subject": {
                    required: true
                },
                "message": {
                    required: true
                }
            },
            messages: {
                "send_to": {
                    required: "<?php echo $this->lang->line('send_to_required')?>"
                },
                "subject": {
                    required: "<?php echo $this->lang->line('subject_required')?>"
                },
                "message": {
                    required: "<?php echo $this->lang->line('message_required') ?>"
                }
            }
        });
    });
</script>